package net.zjitc.servlet.goods;

import net.zjitc.domain.Goods;
import net.zjitc.service.GoodsService;
import net.zjitc.service.impl.GoodsServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet(name = "updateServlet",urlPatterns = "/updateServlet")
public class updateServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request,response);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        GoodsService goodsService=new GoodsServiceImpl();
        request.setCharacterEncoding("UTF-8");
        String id=request.getParameter("id");
        String name=request.getParameter("name");
        String price=request.getParameter("price");
        String info=request.getParameter("info");
        Goods goods=new Goods(Integer.parseInt(id),name,null,Float.parseFloat(price),info);
        int num = goodsService.update(goods);
        String contextPath = request.getContextPath();
        if(num>0){
            response.sendRedirect(contextPath+"/goodsList");
        }
    }
}
